package com.example.demo.interceptor;

import com.alibaba.fastjson.JSON;
import com.example.demo.tools.Result;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Mr.Xi
 * Date: 2023-04-24
 * Time: 20:12
 */

@Configuration
public class MyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        // 没有登录就重定向到 用户登录页面
        response.setStatus(701);
        response.getWriter().print("用户未授权!");
        response.getWriter().flush();
    }
}
